<script setup >
import { ref } from 'vue';
import SingleSelect from './SingleSelect.vue';
import Button from './Button_lxw.vue';

const props = defineProps(['info', 'title', 'map', 'confirmFunction', 'confirmParams', 'cancelFunction', 'cancelParams']);
const edit_info = ref({...props.info})

function confirm() {
    if(props.confirmFunction == undefined) {
        return ;
    }
    props.confirmParams === undefined ? props.confirmFunction.call({edit_info}) : props.confirmFunction.call({edit_info}, props.confirmParams);
}

function cancel() {
    if(props.cancelFunction === undefined) {
        return ;
    }
    props.cancelParams === undefined ? props.cancelFunction.call({edit_info}) : props.cancelFunction.call({edit_info}, props.cancelParams);
}
</script>
<template>
    <div class="modification-form" >
        <div class="title" >{{ props.title }}</div>
        <template v-for="(m, index) in props.map" :key="index" >
                    <div class="input-container" >
                        <div class="item-name" >{{ m['label'] }}</div>
                        <SingleSelect v-if="m['isEnum']" v-model:selected="edit_info[m['key']]" :options="m['enum']" :disabled="!m['isEdit']" />
                        <input v-else  class="input"  :disabled="!m['isEdit']" :class="{edited: edit_info[m['key']] !== props.info[m['key']]}" type="text" v-model="edit_info[m['key']]"  />
                    </div>
        </template>
        <div class="buttons" >
                <Button class="confirm" :style="{margin: '0 15px'}" @click="confirm" >确定</Button>
                <Button class="cancel" :style="{margin: '0 15px'}" @click="cancel" >取消</Button>
            </div>
    </div>
</template>
<style scoped >
.title {
    font-size: 20px;
    margin: 15px auto;
    text-align: center;
    padding: 10px 0;
    border-bottom: 1px solid #C0C4CC;
}

.input-container {
    width: 80%;
    margin: 10px auto;
}

.item-name {
    letter-spacing: 1px;
    font-size: 18px;
}

.item-name::after {
    content: ": "
}

.input {
    width: 100%;
    height: 35px;
    display: inline-block;
    padding: 5px 10px;
    border: none;
    background-color: #f1f1f1;
    letter-spacing: 1px;
    font-size: 16px;
    line-height: 30px;

}

.input:focus {
    outline: none;
    background-color: #C0C4CC;
}

.input.edited {
    background-color:   #f3d19e; 
}

.input.edited:focus {
    outline: none;
    background-color:  #E6A23C;
}

.input:disabled {
    cursor: not-allowed;

}

.buttons {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 15px auto;
}

.confirm {
    width: 120px !important;
    border-color: transparent !important;
    background-color: #8493a6 !important;
    color: #FFFFFF !important;
}

.cancel {
    width: 120px !important;
    border-color: transparent !important;
    background-color: #939393 !important;
    color: #FFFFFF !important;
}

</style>